home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / util / misc / Fudgit233.lha / Source / src / dalloca.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-14  |  1.4 KB  |  68 lines

  1. /* Version of alloc.c using alloca macros instead of alloc */
  2.  
  3. #include <ctype.h>
  4.  
  5. #ifdef __GNUC__
  6. #define alloca __builtin_alloca
  7. #else
  8. #if defined (sparc) || defined (sgi)
  9. #include <alloca.h>
  10. #endif
  11. #endif
  12.  
  13. #ifndef __STDIO_H___
  14. #include <stdio.h>
  15. #endif
  16.  
  17. #ifndef NULL
  18. #define NULL 0
  19. #endif
  20.  
  21. #ifndef ERRR
  22. #define ERRR (-1)
  23. #endif
  24.  
  25. #define ERROR(string, action) {\
  26.     fprintf(stderr, "%s: Allocation error.\n", string);\
  27.     action(ERRR);\
  28. }
  29.  
  30. #define AIVECTOR(v, nl, nh, func, act) { \
  31.     v=(int *)alloca((unsigned) (nh-nl+1) * sizeof(int)); \
  32.     if (v == (int *)NULL) {\
  33.         ERROR(func, act);\
  34.     }\
  35.     v-=nl;\
  36. }
  37.     /* bzero((void *)v, (nh-nl+1) * sizeof(int));\ */
  38.  
  39. #define ADVECTOR(v, nl, nh, func, act) {\
  40.     v=(double *)alloca((unsigned) (nh-nl+1) * sizeof(double)); \
  41.     if (v == (double *)NULL) {\
  42.         ERROR(func, act);\
  43.     }\
  44.     v-=nl;\
  45.     /* bzero((void *)v, (nh-nl+1) * sizeof(double));\ */
  46.  
  47. #define ADMATRIX(m, nrl, nrh, ncl, nch, func, act)  {  \
  48.     double *ddp; \
  49.     int ii;\
  50.  \
  51.     m=(double **)alloca((unsigned) (nrh-nrl+1) * sizeof(double*)); \
  52.     if (m == (double **)NULL) {\
  53.         ERROR(func, act);\
  54.     }\
  55.     m -= nrl; \
  56.  \
  57.     for(ii=nrl;ii<=nrh;ii++) { \
  58.         ddp=(double *)alloca((unsigned) (nch-ncl+1) * sizeof(double)); \
  59.         if (ddp == (double *)NULL) {\
  60.             ERROR(func, act);\
  61.         }\
  62.         m[ii] = ddp - ncl; \
  63.     } \
  64.         /* bzero((void *)ddp, (nch-ncl+1) * sizeof(double));\ */
  65.  
  66.